<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
// 按需引入
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";
import {qd_List} from '@/utils/index'
export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "500px",
    },
    autoResize: {
      type: Boolean,
      default: true,
    },
    chartData: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      chart: null,
      userType: this.$store.state.user.type,
      username: this.$store.state.user.name.username,
    };
  },
  watch: {
    chartData: {
      deep: true,
      handler(val) {
        this.setOptions(val);
      },
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el);
      // this.setOptions(this.chartData)
    },
    setOptions({ date, pv, uv, click,show, z_pv, z_uv, z_click, z_show, uv_date, z_uv_date, click_b, z_click_b, line, uv_click, uv_show, z_uv_click, z_uv_show, r_pv, z_r_pv } = {}) {
      // console.log('uv_b', uv_b)
      var d = [uv_date + "-PV", uv_date + "-UV", uv_date + "-D", uv_date + "-广告点击", uv_date + "-广告展示", uv_date + "-广告点击率"];

      var s = [
        {
          name: uv_date + "-PV",
          itemStyle: {
            normal: {
              color: "#1E90FF",
              lineStyle: {
                color: "#1E90FF",
                width: 3,
              },
            },
          },
          // areaStyle: {
          //   color: "#94e5e7",
          // },
          smooth: true,
          type: "line",
          data: pv,
          animationDuration: 2800,
          animationEasing: "cubicInOut",
        },
        {
          name: uv_date + "-UV",
          smooth: true,
          type: "line",
          itemStyle: {
            normal: {
              color: "#32CD32",
              lineStyle: {
                color: "#32CD32",
                width: 3,
              },
            },
          },
          // areaStyle: {
          //   color: "#fbe38d",
          // },
          data: uv,
          animationDuration: 1500,
          animationEasing: "quadraticOut",
        },
        {
            name: uv_date + "-uv点击",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#FFA500",
                lineStyle: {
                  opacity: 0
                }
              },
            },
            data: uv_click,
          },
          {
            name: uv_date + "-uv展示",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#FFA500",
                lineStyle: {
                  opacity: 0
                }
              },
            },
            data: uv_show,
          },
          {
            name: uv_date + "-人均启动",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#FFA500",
                lineStyle: {
                  opacity: 0
                }
              },
            },
            data: r_pv,
          },
          {
            name: uv_date + "-广告点击",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#FFA500",
                lineStyle: {
                  color: "#FFA500",
                  width: 3,
                }
              },
            },
            data: click,
            animationDuration: 1500,
            animationEasing: "quadraticOut",
          },
          {
            name: uv_date + "-广告展示",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#8A2BE2",
                lineStyle: {
                  color: "#8A2BE2",
                  width: 3,
                },
              },
            },
            data: show,
            animationDuration: 1500,
            animationEasing: "quadraticOut",
          },
          {
            name: uv_date + "-广告点击率",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#FF4500",
                lineStyle: {
                  color: "#FF4500",
                  width: 3,
                },
                // areaStyle: {
                //   color: "#f3f8ff",
                // },
              },
            },
            data: click_b,
            animationDuration: 1500,
            animationEasing: "quadraticOut",
          },
        
      ];
      // console.log('-----', this.username)
      if (this.userType !== "qudao") {

        d = d.concat([z_uv_date + "-PV", z_uv_date + "-UV", z_uv_date + "-D", , z_uv_date + "-广告点击", z_uv_date + "-广告展示", z_uv_date + "-广告点击率"]);
        s = s.concat([
        {
          name: '---------------',
          smooth: true,
          type: "line",
          itemStyle: {
            normal: {
              color: "#a7dbf7",
              lineStyle: {
                color: "#a7dbf7",
                width: 2,
              },
            },
          },
          // areaStyle: {
          //   color: "#77bbe1",
          // },
          data:line,
          animationDuration: 1500,
          animationEasing: "quadraticOut",
        },
        {
          name: z_uv_date + "-PV",
          smooth: true,
          type: "line",
          itemStyle: {
            normal: {
              color: "#1E90FF",
              lineStyle: {
                color: "#1E90FF",
                width: 2,
              },
            },
          },
          // areaStyle: {
          //   color: "#77bbe1",
          // },
          data: z_pv,
          animationDuration: 1500,
          animationEasing: "quadraticOut",
        },
        {
          name: z_uv_date + "-UV",
          smooth: true,
          type: "line",
          itemStyle: {
            normal: {
              color: "#32CD32",
              lineStyle: {
                color: "#32CD32",
                width: 2,
              },
            },
          },
          // areaStyle: {
          //   color: "#77bbe1",
          // },
          data: z_uv,
          animationDuration: 1500,
          animationEasing: "quadraticOut",
        },
        {
            name: z_uv_date + "-uv点击",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#FFA500",
                lineStyle: {
                  opacity: 0
                }
              },
            },
            data: z_uv_click,
          },
          {
            name: z_uv_date + "-uv展示",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#FFA500",
                lineStyle: {
                  opacity: 0
                }
              },
            },
            data: z_uv_show,
          },
          {
            name: z_uv_date + "-人均启动",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#FFA500",
                lineStyle: {
                  opacity: 0
                }
              },
            },
            data: z_r_pv,
          },
          {
            name: z_uv_date + "-广告点击",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#FFA500",
                lineStyle: {
                  color: "#FFA500",
                  width: 2,
                },
                // areaStyle: {
                //   color: "#FFA500",
                // },
              },
            },
            data: z_click,
            animationDuration: 1500,
            animationEasing: "quadraticOut",
          },
          {
            name: z_uv_date + "-广告展示",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#8A2BE2",
                lineStyle: {
                  color: "#8A2BE2",
                  width: 2,
                },
                // areaStyle: {
                //   color: "#8A2BE2",
                // },
              },
            },
            data: z_show,
            animationDuration: 1500,
            animationEasing: "quadraticOut",
          },
          {
            name: z_uv_date + "-广告点击率",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#FF4500",
                lineStyle: {
                  color: "#FF4500",
                  width: 2,
                },
                // areaStyle: {
                //   color: "#f3f8ff",
                // },
              },
            },
            data: z_click_b,
            animationDuration: 1500,
            animationEasing: "quadraticOut",
          },
        ]);
      }
      
      this.chart.setOption({
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            data: date,
          },
        ],
        // {
        //       data: date,
        //       boundaryGap: false,
        //       axisTick: {
        //         show: false,
        //       },
        //     },
        grid: {
          left: 10,
          right: 30,
          bottom: 20,
          top: 30,
          containLabel: true,
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
          },
          padding: [5, 10],
        },
        yAxis: [
          {
            type: "value",
          },
        ],
        legend: {
          data: d,
        },
        series: s,
      });
    },
  },
};
</script>
<style>
.a {
  color: #939394;
}
</style>
